// import 'babel-polyfill'
import Vue from "vue"
import App from "./App"
import router from "./router"
import store from "./store"
import config from "./assets/js/config"
import utils from "./assets/js/utils"
import { request, axios, get, post, $delete } from "./assets/js/request"
import "./assets/css/theme/index.css"
import ElementUI from "element-ui"
Vue.use(ElementUI)
import Print from 'vue-print-nb' //引入
Vue.use(Print);  //全局注册
import iotBlk from "@/components/iot/Blk"
Vue.component("iot-blk", iotBlk)

Vue.config.productionTip = false

Vue.prototype.$axios = axios
Vue.prototype.$ajax = request
Vue.prototype.$get = get
Vue.prototype.$post = post
Vue.prototype.config = config
Vue.prototype.utils = utils
Vue.prototype.initVideoWebPlugin = utils.initVideoWebPlugin
let fullLoading = null
Vue.prototype.openFullLoading = function (tip) {
    fullLoading = this.$loading({
        lock: true,
        text: tip || "加载中...",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.4)",
    })
}
Vue.prototype.closeFullLoading = function (tip) {
    if(fullLoading) fullLoading.close()
}
Vue.prototype.showConfirm = function (tip, confirmCbk) {
    let warnImg = require("./assets/images/icon-warn.png")
    let warnTip = `${tip}<br>如果继续请点击“确定”，否则点击“取消”是否继续？`
    this.$confirm(`<img class="icon" src="${warnImg}"><br>${warnTip}`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        cancelButtonClass: "el-button--cancel",
        dangerouslyUseHTMLString: true,
        customClass: "confirm-msg-box",
    })
        .then(() => {
            confirmCbk && confirmCbk()
        })
        .catch(() => { })
}

Vue.prototype.goBack = function () {
    window.history.length > 1 ? router.go(-1) : router.push("/")
}
Vue.prototype.checkMobile = (rule, value, callback) => {
    var isMobile = /^1[3456789]\d{9}$/
    if (!isMobile.test(value)) {
        callback(new Error("手机号码格式不正确"))
    } else {
        callback()
    }
}
Vue.prototype.validateUrl = (rule, value, callback) => {
    let isValid = true
    let urlHttps = value.slice(0, 8)
    let urlHttp = value.slice(0, 7)
    isValid = value.length > 12 && (urlHttps == "https://" || urlHttp == "http://")
    if (!isValid) {
        callback(new Error("主页格式不正确!"))
    } else {
        callback()
    }
}
Vue.prototype.muteAction = function (item) {
    this.$post("/fireFightingIOT/historicalAlarmInfo/alarmSilencer", {
        number: item.number,
    }).then(
        (res) => {
            this.$message.success("消音成功")
        },
        (err) => {
            if (err.msg) {
                this.$message.error(err.msg)
            }
        }
    )
}
Vue.prototype.getTypeList = function (cbk) {
    this.$get("/fireFightingIOT/historicalAlarmInfo/dictList", {
        groupname: "系统类型",
    }).then((res) => {
        cbk && cbk(res.data)
    })
}
Vue.prototype.hasPermission = (id) => {
    let permissionList = []
    if (store && store.state && store.state.siteInfos) {
        permissionList = store.state.siteInfos.buttonList || []
    }
    return permissionList.indexOf(id) >= 0
}

Vue.filter("time", function (value) {
    if (!value) return ""
    return value.replace("T", " ").substr(0, 19)
})
window.eventBus = new Vue();
new Vue({
    router,
    store,
    render: (h) => h(App),
}).$mount("#app")
